{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 朴素贝叶斯 Naive Bayes\n",
    "\n",
    "> 以贝叶斯定理为基础，用于不同相互独立特征下的分类\n",
    "\n",
    "[搞懂朴素贝叶斯公式](https://blog.csdn.net/fisherming/article/details/79509025)\n",
    "[sklearn文档-朴素贝叶斯](https://sklearn.apachecn.org/docs/master/10.html)\n",
    "\n",
    "\n",
    "优点：\n",
    "\n",
    "（1） 算法逻辑简单,易于实现\n",
    "\n",
    "（2）分类过程中时空开销小\n",
    "\n",
    "缺点：\n",
    "\n",
    " 在属性个数比较多或者属性之间相关性较大时，分类效果不好. 朴素贝叶斯模型假设属性之间相互独立\n",
    "\n",
    "\n",
    "贝叶斯公式："
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "$P(B|A) = P(A|B)P(B) / P(A)$"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 高斯模型"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])\n",
    "Y = np.array([1, 1, 1, 2, 2, 2])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1]\n",
      "[1]\n"
     ]
    }
   ],
   "source": [
    "net = GaussianNB()\n",
    "net.fit(X,Y)\n",
    "print(net.predict([[-0.8,-1]]))\n",
    "\n",
    "net_pf = GaussianNB()\n",
    "net_pf.partial_fit(X,Y,np.unique(Y))\n",
    "print(net.predict([[-0.8,-1]]))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}